local prefab_id = "webbert_pack"
local assets_id = "webbert_pack"

local assets =
{
    Asset( "ANIM", "anim/"..assets_id..".zip"),
    Asset( "ATLAS", "images/inventoryimages/"..assets_id..".xml" ),
}

local prefabs =
{
}



local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddLight()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()
    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank(assets_id)
    inst.AnimState:SetBuild(assets_id)
    inst.AnimState:PlayAnimation("close",true)

    MakeInventoryFloatable(inst, "med", nil, 0.75)

    inst.Light:SetFalloff(0.5)
    inst.Light:SetIntensity(.6)
    inst.Light:SetRadius(1)
    inst.Light:SetColour(92/255, 249/255, 255/255)
    inst.Light:Enable(true)

    inst.entity:SetPristine()

    inst:AddTag("nosteal")

    -- inst.MiniMapEntity:SetIcon(prefab_id..".tex")

    if not TheWorld.ismastersim then
        return inst
    end

    -- inst:AddComponent("talker")
    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = assets_id
    inst.components.inventoryitem.atlasname = "images/inventoryimages/"..assets_id..".xml"
    inst.components.inventoryitem:SetOnDroppedFn(function()
        inst.Light:Enable(true)
    end)
    inst.components.inventoryitem:SetOnPutInInventoryFn(function()
        inst.Light:Enable(false)
    end)

    inst:AddComponent('container')
    inst.components.container:WidgetSetup(prefab_id)

    inst:ListenForEvent('onopen',function (this, data)
        inst.AnimState:PlayAnimation('open',true)
        inst.components.inventoryitem:ChangeImageName("webbert_pack_open")

        inst.AnimState:SetSymbolLightOverride('thumbnail',1)
    end)
    inst:ListenForEvent('onclose',function (this, data)
        inst.AnimState:SetSymbolLightOverride('thumbnail',0)
        inst.AnimState:PlayAnimation('close',true)
        inst.components.inventoryitem:ChangeImageName("webbert_pack")
    end)

    -- inst.OnSave = onsave
    -- inst.OnPreLoad = onpreload

    return inst
end

return Prefab("common/inventory/"..prefab_id, fn, assets, prefabs)